package com.test.demo3;

import jdk.jshell.PersistentSnippet;

public class Person {
    //运行顺序： 静态代码块 > 实例代码块 > 构造方法
    public String name;
    public int age;

    //静态代码块和静态成员变量的执行，取决于书写顺序
    public static String Gender = "female";

    static{
        Person.Gender = "male";
        System.out.println("静态代码块被调用了");
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println("有参的构造方法被调用了");
    }

    public Person() {
        System.out.println("无参的构造方法被调用了");
    }

    //先执行实例代码块，后执行构造方法
    //实例代码块和实例成员变量的执行，取决于书写顺序
    {
        this.name = "nazha";
        this.age = 17;
        System.out.println("实例代码块被执行了，实例代码块主要用于初始化实例数据成员");
    }

    public void work(){
        System.out.println("上班");
    }

    public static String doThing(){
        Person person = new Person();
        person.name = "xiaoming";
        person.age = 17;
        return person.name;
    }
}
